package com.job.DQH.dqh715.inClass;

public class StringEX01 {
    public static void main(String[] args) {
        //练习：找出连续出现最多的字符（若平局则取靠前的）
        String s = "aa111nvBBBB49999wwwwwwww";
        int max = 1;
        int length = 1;
        char maxchar = s.charAt(0) ;

        for (int i = 0; i <s.length()-1 ; i++) {//此处i最多取到s.length-2！！！

            if(s.charAt(i) == s.charAt(i+1)){
                length++;
            }else{
                if(length>max){
                    max = length;
                    maxchar = s.charAt(i);
                }
                length = 1;
            }

        }
        if(max<length){//此处处理最长字符串持续到结尾的情况，此时上面的算法不会计入这个字符串
            maxchar = s.charAt(s.length()-1);
            max = length;
        }
        System.out.println(max+"~"+maxchar);


    }
}
